package com.lab.book.sharding.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lab.book.sharding.service.OrderService;
import com.lab.book.sharding.service.UserService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class ShardingController {

	@Autowired
	private UserService userService;

	@Autowired
	private OrderService orderService;

	@GetMapping("/initUserData")
	public String index() throws Exception {
		userService.insertData();
		return "initUserData OK";
	}

	@GetMapping("/initAddressrData")
	public String index1() throws Exception {
		orderService.initAddressTable();
		return "initAddressrData OK";
	}

	@GetMapping("/initOrderData")
	public String initOrderData() throws Exception {
		orderService.insertData();
		return "initOrderData OK";
	}

	@GetMapping("/printOrderData")
	public String printOrderData() throws Exception {
		orderService.printData();
		return "printOrderData OK";
	}

	@GetMapping("/deleteDataData")
	public String deleteDataData() throws Exception {
		List<Long> orderIds = new ArrayList<Long>();
		orderService.deleteData(orderIds);
		return "deleteDataData OK";
	}

}
